package com.eqxiu.ieditor.manager.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.eqxiu.ieditor.manager.utils.UserContext;

import eqxiu.passport.sdk.dto.UserDTO;
import eqxiu.passport.sdk.user.Passports;

@Component
public class PermissionInterceptor implements HandlerInterceptor {

	@Value("${userinfo.url}")
	private String userInfoUrl;

	protected Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
//		if ("options".equalsIgnoreCase(request.getMethod())) {
//			return true;
//		}
//		UserDTO user = Passports.getUserInfo(request, userInfoUrl);
//		if (user == null || !user.available()) {
//			response.getWriter().print("user not login or user disabled!");
//			return false;
//		}
//
//		UserContext.setUser(user);
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {

	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {

	}

}
